local skel = fk.CreateSkill {
  name = "lb__leiji",
}

Fk:loadTranslationTable {
  ["lb__leiji"] = "垒击",
  --[":lb__leiji"] = "出牌阶段，你可以与一名没有「<b>垒击</b>」牌的角色拼点：<br>"..
  --"若你赢，你将该角色的一张牌明置于其武将牌上，称为「<b>垒击</b>」；<br>"..
  --"若你没赢，你可以摸一张牌或视为对其使用一张【决斗】，然后本回合此技能失效。",
  --9.20
  [":lb__leiji"] = "出牌阶段，你可以与一名没有「<b>垒击</b>」牌的角色拼点：<br>" ..
      "若你赢，你将该角色的一张牌明置于其武将牌上，称为「<b>垒击</b>」；<br>" ..
      "若你没赢，你可以摸一张牌并视为使用一张【决斗】，然后本回合此技能失效。",

  ["lb__leiji-turn"] = "垒击",
  ["#lb__leiji"] = "垒击：你可以与一名没有「<b>垒击</b>」牌的角色拼点",
  --["#lb__leiji-ask"] = "垒击：你可以视为对 %dest 使用一张【决斗】或取消后摸一张牌",
  ["#lb__leiji-ask"] = "垒击：你可以摸一张牌并视为使用一张【决斗】",
  ["#lb__leiji-duel"] = "垒击：请视为使用一张【决斗】",

  ["$lb__leiji1"] = "尝尝这个！",
  ["$lb__leiji2"] = "轮到你了。",
}

skel:addEffect("active", {
  anim_type = "offensive",
  prompt = "#lb__leiji",
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  min_target_num = 1,
  min_card_num = 1,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and player:canPindian(to_select) and #to_select:getPile("lb__leiji") == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local pindian = player:pindian({ target }, skel.name, Fk:getCardById(effect.cards[1]))
    if pindian.results[target].winner == player then
      if target:isNude() then return end
      local c = Fk:getCardById(room:askToChooseCard(player, {
        target = target,
        flag = "he",
        skill_name = skel.name,
      }))
      target:addToPile("lb__leiji", c, true, skel.name, player)
    else
      --[[
      if not room:askToUseVirtualCard(player,{
        name = "duel",
        skill_name = skel.name,
        prompt = "#lb__leiji-ask::"..target.id,
        extra_data = {exclusive_targets = {target.id}},
      }) then
        player:drawCards(1, skel.name)
      end
      --]]
      if room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#lb__leiji-ask" }) then
        player:drawCards(1, skel.name)
        room:askToUseVirtualCard(player, {
          name = "duel",
          skill_name = skel.name,
          prompt = "#lb__leiji-duel",
          cancelable = false,
        })
        room:invalidateSkill(player, skel.name, "-turn")
      end
    end
  end,
})

skel:addLoseEffect(function(self, player, is_death)
  for _, p in ipairs(player.room:getOtherPlayers(player)) do
    if #p:getPile("lb__leiji") > 0 then
      player.room:moveCardTo(p:getPile("lb__leiji"), Card.DiscardPile, nil, fk.ReasonJustMove, "lb__leiji", "lb__leiji",
        true, p)
    end
  end
end)

return skel
